<?
	require ('db.class.php');
	require ('db.conf.php');
	
	$vars = $_POST;
	
	$db = new db();
	$db->user = $DBconf['user'];
	$db->pass = $DBconf['pass'];
	$db->server = $DBconf['server'];
	$db->database = $DBconf['dbname'];
	$db->connect();

	$ret = $db->execute("SELECT `usuario` FROM `usuarios` WHERE `usuario`='".$vars['user']."'");

	if (count($ret)==0 && $vars['pass']==$vars['pass2']) {
		$ret = $db->execute("INSERT INTO `usuarios` (`usuario`, `password`) VALUES ('".$vars['user']."', md5('".$vars['pass']."'))");
		session_start();
		$_SESSION['username'] = $vars['user'];
		$_SESSION['logged'] = true;
		header('location: ../index.php');
	} else {
		header('location: ../register.php');
	}


?>